<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class MY_Email extends CI_Email {	
	function __construct() {
		$config	=	array(
			'useragent'		=>	'PGVietnamWorks.com',
			'mailtype' 		=> 'html',
		);		
		parent::__construct($config);
	}
	
	function send_mail($args = array()){
		$def	= array(
			'from'		=>	'sales@pgvietnamworks.com',
			'cc'			=>	'',
			'ten_site'	=>	'PGVietnamWorks.com',
		);
		$def	=	array_merge($def, $args);
		// print_r($def);die;
		extract($def);
		$ci	=	&get_instance();
		$ci->load->model('message_m', 'message');
		$message	=	$ci->message->get_message_by_slug($slug);
		// echo '<pre>';print_r($message);die;
		if(!$def['to'] || !$message )
			return false;		
		$this->from($def['from'], $ten_site);
		$this->to($def['to']);
		if($def['cc'])
			$this->cc($def['cc']);
		$subject	=	$message->subject;
		$content	=	$message->content;
		foreach($def as $key => $val){
			$subject	= str_replace("{{$key}}", $$key, $subject);
			$content	= str_replace("{{$key}}", $$key, $content);
		}
		$this->subject($subject);
		$this->message($content);
		return 
		$this->send();
		// if($this->send()){
			// echo 'Email sent.';
		// }else{
		  // show_error($this->print_debugger());
		// }
		// echo $this->print_debugger();
		// die;
		//f_~_S%$r0y7e
		// $config = array(
		  // 'protocol' => 'smtp',
		  // 'smtp_host' => 'mail.pgvietnamworks.com',
		  // 'smtp_port' => 25,
		  // 'smtp_user' => 'sales@pgvietnamworks.com', // change it to yours
		  // 'smtp_pass' => 'f_~_S%$r0y7e', // change it to yours
		  // 'mailtype' => 'html',
		  // 'charset' => 'utf-8',
		  // 'wordwrap' => TRUE
		// );
		
		// $config = Array(
			// 'protocol' => 'smtp',
			// 'smtp_host' => 'ssl://web01.123host.vn',
			// 'smtp_port' => 465,
			// 'smtp_user' => 'sales@pgvietnamworks.com',
			// 'smtp_pass' => 'f_~_S%$r0y7e',
			// 'mailtype'  => 'html', 
			// 'charset'   => 'utf-8'
		// );

		// $message = '<strong>Hello, </strong> this is test';
		// $this->load->library('email', $config);
		// $this->email->set_newline("\r\n");
		// $this->email->from('sales@pgvietnamworks.com'); // change it to yours
		// $this->email->to('tanvannguyen18@gmail.com');// change it to yours
		// $this->email->cc('bachho3388@gmail.com'); 
		// $this->email->subject('Resume from JobsBuddy for your Job posting');
		// $this->email->message($message);
		// if($this->email->send()){
			// echo 'Email sent.';
		// }else{
		  // show_error($this->email->print_debugger());
		// }
	}
}